package com.msmall.community.tag;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.StringUtil;
import com.msmall.community.user.model.UserProfile;

public class FieldValueTag extends TagSupport {

	private static final long serialVersionUID = -131181397178917083L;

	private String type; // SALARY  CHARACTEREISE

	private String value;
	
	public int doStartTag() throws JspException {
		return (SKIP_BODY);
	}
	
	public int doEndTag() throws JspException {
		JspWriter writer = pageContext.getOut();
		StringBuffer buf = new StringBuffer();
		try{
			Map<String, String> map = null;
			if("SALARY".equalsIgnoreCase(type)){
				map = UserProfile.SALARY;
			}
			if("CHARACTERISE".equalsIgnoreCase(type)){
				map = UserProfile.CHARACTERISE;
			}
			if("BODYTYPE".equalsIgnoreCase(type)){
				map = UserProfile.BODYTYPE;
			}
			if("SMOKE".equalsIgnoreCase(type)){
				map = UserProfile.SMOKE;
			}
			if("DRINK".equalsIgnoreCase(type)){
				map = UserProfile.DRINK;
			}
			if("ASTERISM".equalsIgnoreCase(type)){
				map = UserProfile.ASTERISM;
			}
			if("BLOODTYPE".equalsIgnoreCase(type)){
				map = UserProfile.BLOODTYPE;
			}
			if("MARRIED".equalsIgnoreCase(type)){
				map = UserProfile.MARRIED;
			}
			if("EDUDEGREE".equalsIgnoreCase(type)){
				map = UserProfile.EDUDEGREE;
			}
			if("EDUSPECIALTY".equalsIgnoreCase(type)){
				map = UserProfile.EDUSPECIALTY;
			}
			if("JOBTITLE".equalsIgnoreCase(type)){
				map = UserProfile.JOBTITLE;
			}
			if("JOBPROFESSION".equalsIgnoreCase(type)){
				map = UserProfile.JOBPROFESSION;
			}
			if("FAVSPORTS".equalsIgnoreCase(type)){
				map = UserProfile.FAVSPORTS;
			}
			if("FAVOTHERS".equalsIgnoreCase(type)){
				map = UserProfile.FAVOTHERS;
			}
			if("gender".equalsIgnoreCase(type)){
				if(!StringUtil.nullOrBlank(value)){
					Short sex = Short.valueOf(value);
					if(sex.compareTo(ConstantDB.GENDER_FEMALE) == 0){
						buf.append("女士");
					}
					if(sex.compareTo(ConstantDB.GENDER_MALE) == 0){
						buf.append("男士");
					}
					if(sex.compareTo(ConstantDB.GENDER_UNKNOWN) == 0){
						buf.append("保密");
					}
				}else{
					buf.append("保密");
				}
			}
			if(map != null && !map.isEmpty() && !StringUtil.nullOrBlank(value)){
				String[] items = value.split(",");
				for(String item : items){
					item = item.trim();
					buf.append(map.get(item)).append("&nbsp;&nbsp;");
				}
			}else{
				if(!"gender".equalsIgnoreCase(type))
					buf.append("保密");
			}
			writer.print(buf.toString());
		}catch(Exception e){
			
		}
		return (SKIP_BODY);
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}
